package org.social.controller;

import java.util.ArrayList;
import java.util.List;

import org.error.GMErrorCode;
import org.social.db.bean.FunctionSwitch;
import org.social.db.cache.FunctionSwitchCache;
import org.social.manager.FunctionSwitchManager;

import com.dal.gm_api.api.IFunctionSwitch;
import com.sojoys.artifact.tools.ToolError;
import com.xiaoleilu.hutool.util.ArrayUtil;

/**
 * 功能开关
 */
public class FunctionSwitchServer implements IFunctionSwitch {

	/**
	 * 添加开关
	 */
	public boolean save(int funType,boolean isOpen, String remarks) {
		FunctionSwitchManager.changeFunctionSwitch(funType, isOpen, remarks);
		return true;
	}

	/**
	 * 移除开关
	 */
	public boolean remove(int... ids) {
		ToolError.isAndTrue(GMErrorCode.PARAM_ERR, "参数异常", ArrayUtil.isEmpty(ids));
		FunctionSwitchManager.remove(ids);
		return true;
	}

	/**
	 * 获取功能开关信息
	 */
	public List<String> getAllFunctionSwitch() {
		List<FunctionSwitch> all = FunctionSwitchCache.me().getCacheAll();

		List<String> result = new ArrayList<>(all.size());

		for (FunctionSwitch funSwitch : all) {
			result.add(funSwitch.toJson());
		}
		return result;
	}

}
